package com.zxq.demo.admin.utils;

import cn.hutool.http.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

/**
 * @author zw
 * @description
 * @email 2408003640@qq.com
 * @date 2025/6/15 01:55
 */
public class JobHttpUtils {
    private static final Logger log = LoggerFactory.getLogger(JobHttpUtils.class);

    public static String triggerJobById(String triggerUrl, Integer jobId){
        try {
            String url = triggerUrl + "?jobId="+ jobId;
            String result = HttpUtil.get(url);
            log.info("任务调度, url: {}, 返回结果: {}", url, result);
            if ("Success".equalsIgnoreCase(result)) {
                return "Success";
            }
            throw new RuntimeException(String.format("任务调度失败, url: %s, 失败原因: %s", url, result));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Error";
    }
}
